import pytest
import os
from datetime import datetime
from app.config.settings import settings
from .framework.logger import test_logger

@pytest.fixture(scope="session")
def auth_token() -> str:
    """获取认证token"""
    from tests.framework.base import BaseTest
    test = BaseTest(f"http://localhost:8000{settings.API_PREFIX}")
    response = test.execute_request(
        "POST",
        "/auth/token",
        json={
            "username": "testuser",
            "password": "testpassword123"
        }
    )
    assert response.status_code == 200
    token = response.json()["access_token"]
    test_logger.test_logger.info("Successfully obtained auth token")
    return token

@pytest.fixture(scope="session")
def auth_headers(auth_token) -> dict:
    """创建带有认证token的请求头"""
    return {"Authorization": f"Bearer {auth_token}"}

# 添加Allure环境信息
def pytest_configure(config):
    config.stash[allure_plugin].environment.update({
        "Base URL": f"http://localhost:8000{settings.API_PREFIX}",
        "Python Version": os.sys.version,
        "Platform": os.sys.platform
    }) 